//
//  ServerController.m
//  ServiceDebianManager
//
//  Created by Léo Lego on 12/05/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ServerController.h"
#import "ServicesManager.h"
@interface ServerController ()

@end

@implementation ServerController
@synthesize hostField;
@synthesize passwdField;
@synthesize portField;
@synthesize panel;
@synthesize host;
@synthesize passwd;
@synthesize port;

-(id) initWithWindowNibName:(NSString *)windowNibName AndMother:(id)Mother{
	if(self = [super initWithWindowNibName:windowNibName]){
		NSLog(@"INIT Controller server");
		mother = Mother;
		host = [[NSString alloc]initWithString:@"host"];
		passwd = [[NSString alloc] initWithString:@"unknow"];
		port = [[NSNumber alloc] initWithInt:22];
	}
	return  self;
}

-(NSString*) description{
	NSString *str = [[NSString alloc] initWithFormat:@"%@:%d --> %@ ",host,port.intValue,passwd];
	return str;
}

-(void)showWindow:(id)sender{
	[super showWindow:sender];
	portField.intValue = port.intValue;
	passwdField.stringValue = passwd;
	[hostField setStringValue:host];
}

-(void)loadWithHost:(NSString *)nHost Pass:(NSString *)nPass Port:(NSNumber *)nPort{
	host = nHost;
	passwd = nPass;
	port = nPort;
}



- (IBAction)changeButton:(id)sender {
	 NSLog(@"ServerController pressed");
	if(portField != 0 && passwdField.stringValue.length != 0 && hostField.stringValue.length != 0){
		NSLog(@"OK");
		host = hostField.stringValue;
		passwd = passwdField.stringValue;
		port = [[NSNumber alloc]initWithInt:portField.intValue];
		[panel setIsVisible:NO];
		NSLog(@"%@",self);
		[mother savePlist];
		[mother unactiveBar];
	} else {
		NSAlert * alert = [[NSAlert alloc] init];
		[alert setMessageText:@"A zone is empty or port is egal to 0 !"];
		[alert runModal];
		
	}

	
}
@end
